﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer;

namespace PresentationLayerWebForms
{
    public partial class SelectDates : ReservationBaseController
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            currentPage = "SelectDate.aspx";

            string roomTypeID = Request.QueryString["roomTypeID"];
            if (!string.IsNullOrEmpty(roomTypeID))
            {
                skipChooseRoomType = true;
                Booking booking = new Booking();
                booking.RoomTypeID = Convert.ToInt32(roomTypeID);

                booking.RoomType = businessComponentsFacade.FindRoomType(Convert.ToInt32(roomTypeID));

                Session["Booking"] = booking;
            }
            else
            {
                skipChooseRoomType = false;
            }

            if (!IsPostBack)
            {
                txtArrivalDate.Text = DateTime.Today.ToString("dd/MM/yyyy");
                txtDepatureDate.Text = DateTime.Today.AddDays(1).ToString("dd/MM/yyyy");
                txtNumberOfNight.Text = "1";
                dplNumberOfRoom.SelectedIndex = 0;
            }
        }

        protected void btnContinue_Click(object sender, EventArgs e)
        {
            Booking booking = (Booking)Session["Booking"];
            if (booking == null)
            {
                booking = new Booking();
            }

            booking.StartDate = DateTime.ParseExact(txtArrivalDate.Text, "dd/MM/yyyy", null);
            booking.EndDate = DateTime.ParseExact(txtDepatureDate.Text, "dd/MM/yyyy", null);
            booking.NoOfRoom = Convert.ToInt32(dplNumberOfRoom.SelectedValue);


            Payment payment = new Payment();

            booking.Payment = payment;

            Voucher voucher = booking.Payment.Voucher;
            string voucherNo = txtVoucherNo.Text;

            if (voucher == null)
            {
                voucher = businessComponentsFacade.GetVoucher(voucherNo);
                payment.Voucher = voucher;
            }
            else
            {

            }

            Session["Booking"] = booking;

            this.NextPage();
        }
    }
}